﻿@using Volo.Abp.AspNetCore.Mvc.UI.Layout
@using Volo.Abp.UI.Navigation
@using EasyAbp.Abp.AspNetCore.Mvc.UI.Theme.LYear.Themes.LYear.Components.Menu
@inject IPageLayout PageLayout
@model ApplicationMenuItem
@{
    var elementId = string.IsNullOrEmpty(Model.ElementId) ? string.Empty : $"id={Model.ElementId}";
    var cssClass = string.IsNullOrEmpty(Model.CssClass) ? string.Empty : Model.CssClass;
    var disabled = Model.IsDisabled ? "disabled" : string.Empty;
    var open = PageLayout.Content.MenuItemName == Model.Name ? "open" : "";
    var childOpen = LeftNavbarMenuViewComponent.ChildActive(Model.Items, PageLayout.Content.MenuItemName) ? "open" : "";
    var url = string.IsNullOrEmpty(Model.Url) ? "#" : Url.Content(Model.Url);
    var active = PageLayout.Content.MenuItemName == Model.Name ? "active" : "";
    var childActive = LeftNavbarMenuViewComponent.ChildActive(Model.Items, PageLayout.Content.MenuItemName) ? "active" : "";

}

@if (Model.IsLeaf)
{
    if (Model.Url != null)
    {
        <li class=" @open @active"> <a class="@cssClass @disabled" href="@url" @elementId><i class="@LeftNavbarMenuViewComponent.ReWriteIcon(Model.Name, Model.Icon)"></i> <span>@Model.DisplayName</span></a> </li>
    }
}
else
{
    <ul class="nav nav-subnav">
        <li class="nav-item nav-item-has-subnav @childOpen">
            <a id="Menu_@(Model.Name)" href="@url"><i class="@LeftNavbarMenuViewComponent.ReWriteIcon(Model.Name, Model.Icon)"></i> <span>@Model.DisplayName</span></a>
            <ul class="nav nav-subnav">
                @foreach (var childMenuItem in Model.Items)
                {
                    @await Html.PartialAsync("~/Themes/LYear/Components/Menu/_MenuItem.cshtml", childMenuItem)
                }
            </ul>
        </li>
    </ul>
}